Add support for -f/--file option to execute SQL from files#1543
Add support for -f/--file option to execute SQL from files#1543DiegoDAF wants to merge 3 commits into
Conversation
This commit adds support for the -f/--file option to pgcli, similar to psql's behavior. Users can now execute SQL commands from files and exit immediately after execution. Features: - Single file execution: pgcli -f file.sql - Multiple files: pgcli -f file1.sql -f file2.sql - Long form: pgcli --file file.sql - Files are executed sequentially - Pager is automatically disabled in file mode - Proper error handling and exit codes Tests included for all scenarios. Made with ❤️ and 🤖 Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
j-bennet
left a comment
There was a problem hiding this comment.
This looks ready to merge, however, I'm wondering, what will happen if the file contains a destructive command (DROP table_name) and destructive_warning is enabled?
Thanks for the review! Short answer: Concretely, with
One detail worth calling out: Happy to add a behave scenario covering the destructive-file case if you'd like it |
The style gate started failing with ruff 0.15.x: the TimeoutExpired handlers bound `as e` without using it (F841), and step_see_command_output decoded cmd_output into `output` but never used it. The command-output step now asserts on the \dt column headers, which are rendered whether or not any tables exist, so it verifies the special command actually produced its listing.
|
There seems to be a persistent failure in the integration scenario: |
Summary
This PR adds support for the
-f/--fileoption to pgcli, implementing psql-compatible behavior for executing SQL commands from files.Features
pgcli -f file.sqlpgcli -f file1.sql -f file2.sqlpgcli --file file.sqlImplementation Details
-f/--filethat accepts multiple file pathsrun_cli()to check for file mode and execute file contents before entering interactive modeecho_via_pager()to disable pager when in file modehandle_watch_command()methodTesting
Comprehensive BDD tests included covering:
-fflag--fileflag-foptions for different filesCompatibility
This implementation follows psql's behavior and maintains backward compatibility with existing functionality.
Made with ❤️ and 🤖 Claude Code